package com.juzi.wopu.web.interceptor;
import java.util.Map;
import com.juzi.wopu.domain.Employee;
import com.juzi.wopu.web.BaseAction;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

/**
 * 在进行登录时进行拦截
 * @author 园
 *
 */
public class LoginInterceptor extends AbstractInterceptor{
	
	private static final long serialVersionUID = 1L;
	
	private String excludeActions;
	
	public LoginInterceptor(){}

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		Object action = invocation.getAction();
		String className=action.getClass().getSimpleName();
		if(excludeActions.indexOf(className)>-1){
			return invocation.invoke();
		}
		
		Map<String, Object> session=ActionContext.getContext().getSession();
		Employee loginUser = (Employee)session.get(BaseAction.USER_IN_SESSION);
		if(loginUser == null){
			return Action.LOGIN;
		}
		// 获取当前访问Action的方法名称
		return invocation.invoke();
	}
	
	public void setExcludeActions(String excludeActions) {
		this.excludeActions = excludeActions;
		System.out.println(excludeActions);
	}
}